package com.sy.live.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;

/**
 * BaseDao
 * 
 * 
 */
public interface IBaseDao
{

	/**
	 * 添加Entity
	 * 
	 * @param t
	 * @return
	 */
	public <T> boolean addEntity(T t);

	/**
	 * 保存Entity
	 * 
	 * @param t
	 * @return
	 */
	public <T> Serializable saveEntity(T t);

	/**
	 * 更新Entity
	 * 
	 * @param t
	 * @return
	 */
	public <T> boolean updateEntity(T t);

	/**
	 * 删除
	 * 
	 * @param t
	 * @return
	 */
	<T> boolean deleteEntity(T t);

	/**
	 * 根据主键查询
	 * 
	 * @param cla
	 * @param pk
	 * @return
	 */
	<T> T findEntityByPK(Class<T> cla, Serializable pk);

	/**
	 * 查询所有的Entity
	 * 
	 * @param cla
	 * @return
	 */
	<T> List<T> findAllEntity(Class<T> cla);

	/**
	 * 根据HQL与约束条件查询
	 * 
	 * @param hql
	 * @param params
	 * @return
	 */
	<T> List<T> findEntityByHql(String hql, Object... params);

	/**
	 * 根据SQL与约束条件更新
	 * 
	 * @param sql
	 * @param params
	 * @return
	 */
	public boolean executeUpdateSQL(final String sql, final Map<String, Object> params);

	/**
	 * 根据SQL与约束条件查询
	 * 
	 * @param sql
	 * @param params
	 * @return
	 */
	<T> List<T> executeListSQL(final String sql, final Map<String, Object> paramMap);

	boolean executeUpdateHQL(String hql, Map<String, Object> paramMap);

	<T> List<T> executeListHQL(String hql, Map<String, Object> paramMap);

	<T> T executeUniqueHQL(final String hql, final Map<String, Object> paramMap);

	<T> T executeUniqueHQL(Class<T> cla);

	/**
	 * 分页
	 * 
	 * @param arg
	 *            需要分页的Class
	 * @param criterions
	 *            限制条件
	 * @param offset
	 *            起始数
	 * @param length
	 *            长度
	 * @return
	 */
	<T> List<T> getListForPage(final Class<T> arg, final Criterion[] criterions, final int offset, final int length);

	/**
	 * 统计个数(限制条件)
	 * 
	 * @param sql
	 * @param params
	 * @return
	 */
	<T> T executeCountListHQL(final String hql, final Map<String, Object> params);

	<T> T executeCountByCriterion(final Class<T> arg, final Criterion[] criterions);

	<T> List<T> executeByCriterion(final Class<T> cla, final Criterion[] criterions);

	<T> List<T> findByCriteria(DetachedCriteria detachedCriteria);

	<T> List<T> findByCriteria(DetachedCriteria detachedCriteria, int first, int max);

	<T> T executeHQLLimit(final String hql, final Map<String, Object> params, final int firstNum, final int maxNum);
}
